package com.xnx3.wangmarket.shop.core.entity;

import static javax.persistence.GenerationType.IDENTITY;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.Table;
import javax.persistence.Version;

import com.xnx3.DateUtil;
import com.xnx3.StringUtil;
import com.xnx3.j2ee.entity.BaseEntity;

/**
 * Order 订单表
 * @author 管雷鸣
 */
@Entity()
@Table(name = "shop_order", indexes={@Index(name="suoyin_index",columnList="no,storeid,userid,state")})
public class Order extends BaseEntity implements java.io.Serializable{
	/**
	 * 刚下单，待骑手结单
	 */
	public static final String STATE_DAIJIEDAN = "1";	
	/**
	 * 骑手接单,待取货
	 */
	public static final String STATE_DAIQUHUO = "2";	
	/**
	 * 订单已完成,待评价
	 */
	public static final String STATE_FINISH = "3";
	/**
	 * 订单已取消
	 */
	public static final String STATE_CANCEL = "4";
	/**
	 * 订单已完成,已评价
	 */
	public static final String STATE_EVALUATED = "5";
	
	private Integer id;			//订单id
	private String no;			//订单号，这个是支付宝支付、微信支付传过去的订单号，也是给用户显示出来的订单号
	private Integer storeid;	//商家id，这个订单购买的商品是哪个商家的。如果一次购买多个店铺的商品，那么最终订单会分解为每个店铺一个订单
	private Integer addtime;	//订单创建时间，10为时间戳
	private Integer totalMoney;	//预计金额，用户下单时自动给客户预估的一个金额，单位是分
	private Integer payMoney;		//需要实际支付的金额,单位：分
	private Integer payTime;	//该订单完成的时间，10位时间戳，完成时间
	private Integer userid;		//该订单所属的用户，是哪个用户下的单，对应 User.id
	private String state;		//订单状态，服务状态， 1待接单；2待取货，3已完成待评价，4已取消,5已完成已评价
	private String remark;		//用户备注，限制100个字符
	
	/** 斑马回收相关添加 */
	private String address;	//用户填写的取货地址，如山东省潍坊市奎文区世纪环球中心xxxx室
	private String username;	//用户填写名字，出售人的姓名（斑马回收增加）
	private String phone;	//用户电话，出售人电话.（斑马回收增加）
	private Integer reserveStartTime;	//预约日期，预约时间段的开始时间，10位时间戳，这里存的时间戳将会格式化为具体的日期显示。（斑马回收增加）
	private Integer reserveEndTime;	//预约日期，预约时间段的结束时间，10位时间戳，这里存的时间戳将会格式化为具体的日期显示。（斑马回收增加）
	private String qishouName;	//接单的骑手姓名，如果还没有骑手接单，这里就是空的。有骑手接单后，会将qishou.name 赋予此（斑马回收增加）
	private String qishouPhone;	//骑手电话。如果还没有骑手接单，这里就是空的。有骑手接单后，会将qishou.name 赋予此（斑马回收增加）
	private Integer qishouId;	//骑手id。如果还没有骑手接单，这里就是0。有骑手接单后，会将qishou.id 赋予此（斑马回收增加）
	private Integer allWeight;	//该订单内商品的总重量，单位是g，注意是g不是kg
	private String cancelReason;	//订单如果取消，这里是取消的理由。如果未取消，那这里就没有信息.(预留,暂未用到)
	private String userHead;	//订单中下单用户的头像
	private String qishouHead;	//订单中接单骑手的头像
	private String sheng;		//所在的省，如 山东省
	private String shi;			//所在的市，如 潍坊市
	private String qu;			//所在的区，如 寒亭区
	private Integer dailishangUserid;	//代理商用户id,关联user.id
	private Integer wanggeUserid;	//网格用户id,关联user.id
	private String dailishangUsername;	//代理商名称,关联user.nickname
	private String wanggeUsername;	//网格名称,关联user.nickname
	private Integer evaluationScore;	//订单评分, 最高5分,和订单评价记录的订单评分一样 例如: 3.5分  这里是35, 默认5分,即50
	private String orderEvaluation;	//订单评价,用户评语
	
	//购买的商品是什么规格，这里是规格的名字。如果商品没有规格，那这里则是空字符串。 v1.6增加
	private String specificationName;	
	private Integer isNew;	// 是新\老用户下单 0:老用户,1:新用户
	private Integer isLine;	// 订单支付方式: 是线下\线上下单 0:线下,1:线上
	
	private Integer version;	//乐观锁
	
	public Order() {
		this.no = (StringUtil.intTo36(DateUtil.timeForUnix10())+StringUtil.getRandom09AZ(4)).toUpperCase() ; //小写字母变大写
		this.storeid = 1;
	}
	
	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "id", unique = true, nullable = false)
	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}
	@Column(name = "dailishangUsername", columnDefinition="char(100) comment '代理商名称,关联user.nickname'")
	public String getDailishangUsername() {
		return dailishangUsername;
	}

	public void setDailishangUsername(String dailishangUsername) {
		this.dailishangUsername = dailishangUsername;
	}
	@Column(name = "wanggeUsername", columnDefinition="char(100) comment '网格名称,关联user.nickname'")
	public String getWanggeUsername() {
		return wanggeUsername;
	}

	public void setWanggeUsername(String wanggeUsername) {
		this.wanggeUsername = wanggeUsername;
	}

	@Column(name = "no", columnDefinition="char(10) comment '订单号，这个是支付宝支付、微信支付传过去的订单号，也是给用户显示出来的订单号'")
	public String getNo() {
		return no;
	}

	public void setNo(String no) {
		this.no = no;
	}
	
	@Column(name = "storeid", columnDefinition="int(11) comment '商家id，这个订单购买的商品是哪个商家的。如果一次购买多个店铺的商品，那么最终订单会分解为每个店铺一个订单'")
	public Integer getStoreid() {
		return storeid;
	}

	public void setStoreid(Integer storeid) {
		this.storeid = storeid;
	}

	@Column(name = "addtime", columnDefinition="int(11) comment '订单创建时间，10为时间戳'")
	public Integer getAddtime() {
		return addtime;
	}

	public void setAddtime(Integer addtime) {
		this.addtime = addtime;
	}
	
	@Column(name = "total_money", columnDefinition="int(11) comment '预计金额，用户下单时自动给客户预估的一个金额，单位是分'")
	public Integer getTotalMoney() {
		return totalMoney;
	}

	public void setTotalMoney(Integer totalMoney) {
		this.totalMoney = totalMoney;
	}
	
	@Column(name = "pay_money", columnDefinition="int(11) comment '需要实际支付的金额,单位：元'")
	public Integer getPayMoney() {
		if(payMoney == null) {
			return 0;
		}
		return payMoney;
	}

	public void setPayMoney(Integer payMoney) {
		this.payMoney = payMoney;
	}
	
	@Column(name = "pay_time", columnDefinition="int(11) comment '该订单完成的时间，10位时间戳，完成时间'")
	public Integer getPayTime() {
		return payTime;
	}

	public void setPayTime(Integer payTime) {
		this.payTime = payTime;
	}
	
	@Column(name = "userid", columnDefinition="int(11) comment '该订单所属的用户，是哪个用户下的单，对应 User.id'")
	public Integer getUserid() {
		return userid;
	}

	public void setUserid(Integer userid) {
		this.userid = userid;
	}

	@Column(name = "state", columnDefinition="char(20) comment '订单状态，服务状态， 1待接单；2待取货，3已完成待评价，4已取消,5已完成已评价'")
	public String getState() {
		return state;
	}

	public void setState(String state) {
		this.state = state;
	}
	
	@Column(name = "remark", columnDefinition="char(100) comment '买家的备注'")
	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}
	
	@Version
	@Column(name = "version", columnDefinition="int(11) comment '乐观锁' default 0")
	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}
	
	@Column(name = "specification_name", columnDefinition="char(30) comment '购买的商品是什么规格，这里是规格的名字。如果商品没有规格，那这里则是空字符串'")
	public String getSpecificationName() {
		if(this.specificationName == null) {
			this.specificationName = "";
		}
		return specificationName;
	}

	public void setSpecificationName(String specificationName) {
		this.specificationName = specificationName;
	}
	@Column(name = "address", columnDefinition="char(100) COLLATE utf8mb4_general_ci COMMENT '用户填写的取货地址，如山东省潍坊市奎文区世纪环球中心xxxx室' default ''")
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	@Column(name = "username", columnDefinition="char(20) COLLATE utf8mb4_general_ci COMMENT '用户填写名字，出售人的姓名（斑马回收增加）' default ''")
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	@Column(name = "phone", columnDefinition="char(20) COLLATE utf8mb4_general_ci COMMENT '用户电话，出售人电话.（斑马回收增加）' default ''")
	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
	@Column(name = "reserve_start_time", columnDefinition="int(11) COMMENT '预约日期，预约时间段的开始时间，10位时间戳，这里存的时间戳将会格式化为具体的日期显示。（斑马回收增加）' default '0'")
	public Integer getReserveStartTime() {
		return reserveStartTime;
	}
	public void setReserveStartTime(Integer reserveStartTime) {
		this.reserveStartTime = reserveStartTime;
	}
	@Column(name = "reserve_end_time", columnDefinition="int(11) COMMENT '预约日期，预约时间段的结束时间，10位时间戳，这里存的时间戳将会格式化为具体的日期显示。（斑马回收增加）' default '0'")
	public Integer getReserveEndTime() {
		return reserveEndTime;
	}
	public void setReserveEndTime(Integer reserveEndTime) {
		this.reserveEndTime = reserveEndTime;
	}
	@Column(name = "qishou_name", columnDefinition="char(30) COLLATE utf8mb4_general_ci COMMENT '接单的骑手姓名，如果还没有骑手接单，这里就是空的。有骑手接单后，会将qishou.name 赋予此（斑马回收增加）' default ''")
	public String getQishouName() {
		return qishouName;
	}
	public void setQishouName(String qishouName) {
		this.qishouName = qishouName;
	}
	@Column(name = "qishou_phone", columnDefinition="char(11) COLLATE utf8mb4_general_ci COMMENT '骑手电话。如果还没有骑手接单，这里就是空的。有骑手接单后，会将qishou.name 赋予此（斑马回收增加）' default ''")
	public String getQishouPhone() {
		return qishouPhone;
	}
	public void setQishouPhone(String qishouPhone) {
		this.qishouPhone = qishouPhone;
	}
	@Column(name = "qishou_id", columnDefinition="int(11) COMMENT '骑手id。如果还没有骑手接单，这里就是0。有骑手接单后，会将qishou.id 赋予此（斑马回收增加）' default '0'")
	public Integer getQishouId() {
		return qishouId;
	}
	public void setQishouId(Integer qishouId) {
		this.qishouId = qishouId;
	}
	@Column(name = "all_weight", columnDefinition="int(11) COMMENT '该订单内商品的总重量，单位是g，注意是g不是kg' default '0'")
	public Integer getAllWeight() {
		return allWeight;
	}
	public void setAllWeight(Integer allWeight) {
		this.allWeight = allWeight;
	}
	@Column(name = "cancel_reason", columnDefinition="char(200) COLLATE utf8mb4_general_ci COMMENT '订单如果取消，这里是取消的理由。如果未取消，那这里就没有信息.(预留,暂未用到)' default ''")
	public String getCancelReason() {
		return cancelReason;
	}
	public void setCancelReason(String cancelReason) {
		this.cancelReason = cancelReason;
	}
	@Column(name = "user_head", columnDefinition="char(200) COLLATE utf8mb4_general_ci COMMENT '订单中下单用户的头像' default ''")
	public String getUserHead() {
		return userHead;
	}

	public void setUserHead(String userHead) {
		this.userHead = userHead;
	}
	@Column(name = "qishou_head", columnDefinition="char(200) COLLATE utf8mb4_general_ci COMMENT '订单中接单骑手的头像' default ''")
	public String getQishouHead() {
		return qishouHead;
	}

	public void setQishouHead(String qishouHead) {
		this.qishouHead = qishouHead;
	}
	@Column(name = "sheng", columnDefinition="char(20) comment '所在的省，如 山东省' default ''")
	public String getSheng() {
		return sheng;
	}

	public void setSheng(String sheng) {
		this.sheng = sheng;
	}
	@Column(name = "shi", columnDefinition="char(20) comment '所在的市，如 潍坊市' default ''")
	public String getShi() {
		return shi;
	}

	public void setShi(String shi) {
		this.shi = shi;
	}
	@Column(name = "qu", columnDefinition="char(20) comment '所在的区，如 寒亭区' default ''")
	public String getQu() {
		return qu;
	}

	public void setQu(String qu) {
		this.qu = qu;
	}
	@Column(name = "dailishang_userid", columnDefinition="int(11) COMMENT '代理商用户id,关联user.id' default '0'")
	public Integer getDailishangUserid() {
		return dailishangUserid;
	}
	public void setDailishangUserid(Integer dailishangUserid) {
		this.dailishangUserid = dailishangUserid;
	}
	@Column(name = "wangge_userid", columnDefinition="int(11) COMMENT '网格用户id,关联user.id' default '0'")
	public Integer getWanggeUserid() {
		return wanggeUserid;
	}
	public void setWanggeUserid(Integer wanggeUserid) {
		this.wanggeUserid = wanggeUserid;
	}
	@Column(name = "is_new", columnDefinition="int(3) COMMENT '是新/老用户下单 0:老用户,1:新用户' default '0'")
	public Integer getIsNew() {
		return isNew;
	}

	public void setIsNew(Integer isNew) {
		this.isNew = isNew;
	}
	@Column(name = "evaluation_score", columnDefinition="int(3) COMMENT '订单评分, 最高5分,和订单评价记录的订单评分一样 例如: 3.5分  这里是35, 默认5分,即50' default '50'")
	public Integer getEvaluationScore() {
		return evaluationScore;
	}

	public void setEvaluationScore(Integer evaluationScore) {
		this.evaluationScore = evaluationScore;
	}

	
	@Column(name = "order_evaluation", columnDefinition="char(255) COMMENT '订单评价,用户评语' default ''")

	public String getOrderEvaluation() {
		return orderEvaluation;
	}

	public void setOrderEvaluation(String orderEvaluation) {
		this.orderEvaluation = orderEvaluation;
	}
	
	@Column(name = "is_line", columnDefinition="int(3) COMMENT '订单支付方式: 是线下/线上下单 0:线下,1:线上' default '0'")
	public Integer getIsLine() {
		return isLine;
	}

	public void setIsLine(Integer isLine) {
		this.isLine = isLine;
	}

	@Override
	public String toString() {
		return "Order [id=" + id + ", no=" + no + ", storeid=" + storeid + ", addtime=" + addtime + ", totalMoney="
				+ totalMoney + ", payMoney=" + payMoney + ", payTime=" + payTime + ", userid=" + userid + ", state="
				+ state + ", remark=" + remark + ", address=" + address + ", username=" + username + ", phone=" + phone
				+ ", reserveStartTime=" + reserveStartTime + ", reserveEndTime=" + reserveEndTime + ", qishouName="
				+ qishouName + ", qishouPhone=" + qishouPhone + ", qishouId=" + qishouId + ", allWeight=" + allWeight
				+ ", cancelReason=" + cancelReason + ", userHead=" + userHead + ", qishouHead=" + qishouHead
				+ ", sheng=" + sheng + ", shi=" + shi + ", qu=" + qu + ", dailishangUserid=" + dailishangUserid
				+ ", wanggeUserid=" + wanggeUserid + ", dailishangUsername=" + dailishangUsername + ", wanggeUsername="
				+ wanggeUsername + ", evaluationScore=" + evaluationScore + ", orderEvaluation=" + orderEvaluation
				+ ", specificationName=" + specificationName + ", isNew=" + isNew + ", isLine=" + isLine + ", version="
				+ version + "]";
	}

	
	
}